#!/bin/bash
###############################################################################
# @用例ID: 20231121-171642-458896514
# @用例名称: test_mtr_qq_com
# @用例级别: 3
# @用例标签:
# @扩展属性:
# @用例类型: 功能测试
# @自动化: 1
# @超时时间: 0
# @用例描述: TODO: 简要描述用例测试的内容
###############################################################################
[ -z "$TST_TS_TOPDIR" ] && {
    TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")"
    export TST_TS_TOPDIR
}
source "${TST_TS_TOPDIR}/tst_common/lib/common.sh" || exit 1
###############################################################################

g_tmpdir="$(mktemp -d)"

tc_setup() {
    msg "this is tc_setup"

    # @预置条件: 安装 mtr
    assert_true yum install -y mtr
}

do_test() {
    msg "this is do_test"
    cd $g_tmpdir

    # @测试步骤: mtr 访问 qq.com
    mtr -r qq.com -c 1 > qqcom.txt
    # @预期结果: 运行成功,并返回多行结果
    assert_true [ $? -eq 0 ]

    # 输出预期 
    # Start: Tue Nov 21 17:24:29 2023
    # HOST: VM_32_148_centos           Loss%   Snt   Last   Avg  Best  Wrst StDev
    #  1.|-- 9.134.182.59               0.0%     1    0.3   0.3   0.3   0.3   0.0
    #  2.|-- 9.31.73.59                 0.0%     1    0.4   0.4   0.4   0.4   0.0
    #  3.|-- ???                       100.0     1    0.0   0.0   0.0   0.0   0.0
    #  4.|-- ???                       100.0     1    0.0   0.0   0.0   0.0   0.0
    #  5.|-- 10.196.18.109              0.0%     1    1.1   1.1   1.1   1.1   0.0
    #  6.|-- 10.196.92.109              0.0%     1    1.3   1.3   1.3   1.3   0.0
    #  7.|-- 10.196.93.230              0.0%     1    1.0   1.0   1.0   1.0   0.0
    #  8.|-- 10.196.2.102               0.0%     1   27.7  27.7  27.7  27.7   0.0
    #  9.|-- 10.200.9.189               0.0%     1   28.9  28.9  28.9  28.9   0.0
    # 10.|-- 10.162.86.157              0.0%     1   35.7  35.7  35.7  35.7   0.0
    # 11.|-- 10.196.39.78               0.0%     1   28.5  28.5  28.5  28.5   0.0
    # 12.|-- 30.62.66.29                0.0%     1   32.2  32.2  32.2  32.2   0.0
    # 13.|-- 113.108.81.189             0.0%     1   29.0  29.0  29.0  29.0   0.0
    # 判断大于 3 行
    assert_true [ `wc -l < qqcom.txt` -gt 3 ]

    # 第一行包含Start
    head qqcom.txt -n 1 | grep Start
    assert_true [ $? -eq 0 ]

    grep HOST qqcom.txt
    assert_true [ $? -eq 0 ]

    grep Loss qqcom.txt
    assert_true [ $? -eq 0 ]

    return 0
}

tc_teardown() {
    msg "this is tc_teardown"
    rm -rfv "$g_tmpdir" || return 1
    return 0
}

###############################################################################
tst_main "$@"
###############################################################################
